import java.util.Arrays;
import java.util.Comparator;

/**
 * @Description
 */

public class Test {
    //比较器
    public static void main(String[] args) {
        AgeComparator ageComparator = new AgeComparator();
        Student[] students = new Student[2];

        students[0] = new Student("小明",12,"115");
        students[1] = new Student("小花",13,"113");
        Arrays.sort(students,ageComparator);
        System.out.println(Arrays.toString(students));

    }
    public static void bubbleSort(Comparable[] comparable) {
        //实现排序
        for (int i = 0; i < comparable.length - 1; i++) {
            for (int j = 0; j < comparable.length - 1 - i; j++) {
                //<0则为从大到小排序
                if (comparable[j].compareTo(comparable[j + 1]) > 0) {
                    Comparable tmp = comparable[j];
                    comparable[j+1] = tmp;
                    comparable[j] = comparable[j+1];

                }

            }
        }
    }

    public static void main2(String[] args) {
        //comparable方法
        Student[] students = new Student[2];

        students[0] = new Student("小明",12,"115");
        students[1] = new Student("小花",13,"113");
//        Arrays.sort(students);
        bubbleSort(students);
        System.out.println(Arrays.toString(students));
    }

    public static void main1(String[] args) {
        Student student1 = new Student("小明",12,"115");
        Student student2 = new Student("小花",13,"113");
        AgeComparator ageComparator = new AgeComparator();
       /* if(student1.compareTo(student2)>0){
            System.out.println("student1>student2");
        }else{
            System.out.println("student1<student2");
        }*/
        if(ageComparator.compare(student1,student2)>0){
            System.out.println("student1>student2");

        }else{
            System.out.println("student1<student2");
        }
        nameComparator nameComparator = new nameComparator();
        int ret = nameComparator.compare(student1, student2);
        System.out.println(ret);

    }
}
